package com.molichuxing.services.infrastructure.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.molichuxing.services.infrastructure.bean.ReceiptCompanyBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.ReceiptCompanyBankMapper;
import com.molichuxing.services.infrastructure.dao.ReceiptCompanyMapper;
import com.molichuxing.services.infrastructure.dto.response.ReceiptCompanyDto;
import com.molichuxing.services.infrastructure.service.ReceiptCompanyService;

@Service("receiptCompanyService")
public class ReceiptCompanyServiceImpl implements ReceiptCompanyService {
	private static final Logger logger = LoggerFactory.getLogger(ReceiptCompanyServiceImpl.class);

	@Resource
	private ReceiptCompanyMapper receiptCompanyMapper;

	@Resource
	private ReceiptCompanyBankMapper receiptCompanyBankMapper;

	/**
	 * 获取所有收款方公司信息
	 * 
	 * @return
	 */
	@Override
	public List<ReceiptCompanyDto> getReceiptCompany() {
		List<ReceiptCompanyDto> result = null;

		List<ReceiptCompanyBean> receiptCompanys = receiptCompanyMapper.getAll();
		if (receiptCompanys == null || receiptCompanys.isEmpty()) {
			return result;
		}

		result = new ArrayList<>();
		for (ReceiptCompanyBean receiptCompany : receiptCompanys) {
			ReceiptCompanyDto receiptCompanyDto = Convert.toReceiptCompanyDto(receiptCompany);
			receiptCompanyDto.setBanks(
					Convert.toReceiptCompanyBankDto(receiptCompanyBankMapper.getByCompany(receiptCompany.getId())));

			result.add(receiptCompanyDto);
		}

		return result;
	}

}
